//2 3 3 1 x，y，cntx，cnty。
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let x, y, cntx, cnty;
rl.on("line", (line)=>{
    if(x === undefined) {
            [x, y, cntx, cnty] = line.trim().split(" ").map(Number)
        console.log(getResult(x, y, cntx, cnty))
        //clear
        x = y = cntx = cnty = undefined
    }
})

function getResult(x, y, cntx, cnty) {
    let common =  x*y/handXY(x, y)     // 公因数
    // x需要的人数
    let min = cntx  + cnty
    let max = 1e9
    let result = Infinity;
    while(min <= max) {
        let mid = Math.floor((min + max)/2)
        if(valid(mid, y, x, cntx, cnty, common)) {
            result = Math.min(result, mid)
            max = mid - 1
        } else {
            min = mid+1
        }
    }

    return result
}

function handXY(x, y) {
    return y === 0 ? x : handXY(y, x%y)
}

function valid(mid, y, x, cntx, cnty, common) {
   let a = Math.floor(mid/y)
   let b = Math.floor(mid/x)
    let c = Math.floor(mid/common)
   return  Math.max(0, cntx - (a - c)) + Math.max(0, cnty - (b - c)) <= mid - (a + b) + c
}